@extends('Admin.layout.layout')

@section('content')
<div class="col-lg-12">
    <div class="panel panel-default">
        <div class="panel-heading">
        用户列表
        </div> 

<div class="panel-body">
    <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
    	<div class="row">
    	<form action="{{url('/admin/user/index')}}" method="get">
    		<div class="col-sm-6">
    			<div id="dataTables-example_filter" class="dataTables_filter">
     				<label>用户名:<input class="form-control input-sm" placeholder="" aria-controls="dataTables-example" name="word" type="search"> <button type="submit" class="btn btn-primary">搜索</button></label>
    			</div>
    		</div>
    	</form>
    	</div>
    	<div class="row">
        <!-- /.panel-heading -->
        <div class="panel-body">
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>id</th>
                            <th>顶级分类</th>
                            <th>分类路径</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    @foreach($cates as $k=>$v)
                        <tr class="success">
                            <td class="sid">{{$v->id}}</td>
                            <td>{{$v->name}}</td>
                            <td>{{$v->path}}</td>
                            <td><p class="fa fa-trash-o"></p><a class="delete" href
                            ="">删除</a> | <p class="fa fa-wrench"></p><a href="{{url('/admin/cate/edit',['id' => $v -> id])}}">修改</a></td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
            <!-- /.table-responsive -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->


</div>  

@endsection

@section('myjs')
<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
    $('.delete').click(function(){
        var id = $(this).parents('tr').find('.sid').html();
        // 发送ajax
        var tr = $(this);
        $.post('/admin/cate/delete',{id:id},function(data){
            if(data == 2){
                tr.parents('tr').remove();
                message('success','分类删除成功');
            }else if(data == 1){
                message('error','不能删除');
            }else{
                message('error','删除失败');
            }
        })
        return false;
    })
    function message(er,m){
        if(er == 'success'){
            $('#messagesuccess').find('span').html(m);
            $('#messagesuccess').show();
        }else{
            $('#messagedanger').find('span').html(m);
            $('#messagedanger').show();
        }
    }
</script>
@endsection
